cmake_minimum_required(VERSION 3.15)

project(CameraTest)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
find_package(wxWidgets REQUIRED COMPONENTS net core base)
find_package(fmt REQUIRED)
find_package(lz4 REQUIRED)
find_package(oatpp REQUIRED)
find_package(oatpp-websocket REQUIRED)
include(${wxWidgets_USE_FILE})

file(GLOB SourceCode "src/*.cpp" "src/*.h")

file(GLOB CameraLib_x86 "lib/x86_64/*.so")
file(GLOB CameraLib_arm "lib/arm/*.so")
file(GLOB CameraLib_armhf "lib/armhf/*.so")
set(CameraLib
    ${CameraLib_x86}
    CACHE PATH "Camera library" FORCE)

add_executable(CameraTest ${SourceCode})

if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
  message("You are using debug profile.")
  target_compile_options(
    CameraTest
    INTERFACE
      "$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>>"
  )
else()
  message("You are using release profile.")
  if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
    message("Enable optimize for aarch64")
    target_compile_options(
      CameraTest
      INTERFACE
        "$<${gcc_like_cxx}:$<BUILD_INTERFACE:-ftree-vectorize;–mfpu=neon;-Wall>>"
    )
    set(CameraLib ${CameraLib_arm})
  elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "armv7l")
    message("Enable optimize for aarch64")
    target_compile_options(
      CameraTest
      INTERFACE
        "$<${gcc_like_cxx}:$<BUILD_INTERFACE:-ftree-vectorize;–mfpu=neon;-Wall>>"
    )
    set(CameraLib ${CameraLib_armhf})
  else()
    target_compile_options(
      CameraTest INTERFACE "$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall>>")
  endif()
endif()
message(STATUS "Find CameraLib: ${CameraLib}")

target_include_directories(CameraTest PUBLIC "inc")
target_link_libraries(
  CameraTest
  PUBLIC ${wxWidgets_LIBRARIES}
         ${CameraLib}
         oatpp::oatpp
         oatpp::oatpp-websocket
         fmt
         pthread
         lz4)

add_subdirectory("tool/DecompOldCSS")
add_subdirectory("tool/ImageHandleDemo")
add_subdirectory("tool/UpdateOldCCS")
add_subdirectory("tool/RemoteControl")
add_subdirectory("tool/RemoteClient")
add_subdirectory("tool/DecompCSS")
add_subdirectory("tool/DecompCSSList")
